﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QChart *chart=new QChart();
    chart->setTitle("曲线图示例");
    //
    QLineSeries *series=new QLineSeries();
    series->append(QPoint(0,8));
    series->append(QPoint(1,7));
    series->append(QPoint(2,8));
    series->append(QPoint(3,5));
    series->append(QPoint(4,7));
    series->append(QPoint(5,3));
    series->setName("曲线A");
    //
    chart->addSeries(series);
    chart->createDefaultAxes();
    chart->axisX()->setTitleText("X轴");
    chart->axisY()->setTitleText("Y轴");
    //QChartView *chartView=new QChartView(chart);
    ui->widget_3->setRenderHint(QPainter::Antialiasing);//看锯齿必须
    ui->widget_3->setChart(chart);

    //
    QChart *chart_2=new QChart();
    chart_2->setTitle("柱形图");

    QBarSet *set1=new QBarSet("wxx");
    QBarSet *set2=new QBarSet("wjj");
    QBarSet *set3=new QBarSet("jhj");

    *set1<<1<<3<<5<<7<<9;
    *set2<<2<<4<<5<<3<<8;
    *set3<<3<<3<<2<<4<<5;

    QBarSeries *series_2=new QBarSeries();
    series_2->append(set1);
    series_2->append(set2);
    series_2->append(set3);

   chart_2->addSeries(series_2);
   QBarCategoryAxis *axis=new QBarCategoryAxis();
   axis->append(QStringList()<<"wxx"<<"wjj"<<"jhj");

   chart_2->addAxis(axis,Qt::AlignLeft);
   series_2->attachAxis(axis);
   ui->widget_2->setChart(chart_2);

   QPieSeries *series_3=new QPieSeries();
   series_3->append("wxx 1",10);
   series_3->append("jhj",40);
   series_3->append("wjj",50);
   chart=new QChart();
   chart->addSeries(series_3);
   chart->setTitle("pie");
   chart->setAnimationOptions(QChart::AllAnimations);
   ui->widget->setChart(chart);
}

MainWindow::~MainWindow()
{
    delete ui;
}

